package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.pubdef.dto.activity.ActivityContentConfigDTO;
import com.qumitech.visualnovel.service.activity.ActivityContentConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @className: ActivityContentConfigController
 * @description:
 * @author: bzhao
 * @date: 2020/10/10 8:45 下午
 * copyright(c) 2017-2020 趣米（武汉）科技有限公司
 */
@RestController
@RequestMapping("/api/activity_content")
public class ActivityContentConfigController {

    @Autowired
    ActivityContentConfigService activityContentConfigService;


    @GetMapping("/config")
    public BaseRsp listActivityContentConfig(@RequestParam(value = "limit", required = false, defaultValue = "20") String limit,
                                             @RequestParam(value = "offset", required = false, defaultValue = "0") String offset,
                                             @RequestParam(value = "act_id", required = false) Integer actId,
                                             @RequestParam(value = "act_name", required = false) String actName,
                                             @RequestParam(value = "online", required = false) Byte online,
                                             @RequestParam(value = "html", required = false) String html) {
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("limit", limit);
        paramMap.put("offset", offset);
        if (actId != null) {
            paramMap.put("act_id", String.valueOf(actId));
        }
        paramMap.put("act_name", actName);
        if (online != null) {
            paramMap.put("online", String.valueOf(online));
        }
        paramMap.put("html", html);
        return activityContentConfigService.listActivityContentConf(paramMap);
    }

    @PutMapping("/config")
    public BaseRsp addActivityContentConfig(@RequestBody ActivityContentConfigDTO dto) {
        activityContentConfigService.saveActivityContentConf(dto);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @PostMapping("/config")
    public BaseRsp editActivityContentConfig(@RequestBody ActivityContentConfigDTO dto) {
        activityContentConfigService.updateActivityContentConf(dto);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @DeleteMapping("/config")
    public BaseRsp deleteActivityContentConfig(@RequestParam(value = "act_id") Integer actId) {
        ActivityContentConfigDTO dto = new ActivityContentConfigDTO();
        dto.setActId(actId);
        activityContentConfigService.deleteActivityContentConf(dto);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

}
